<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="css/login.css">

</head>

<body>
<div class="loginBox">
    <h2>登录</h2>
    <form action="LoginHandler.php" method="post" id="loginForm">
        <div class="item">
            <input type="text" id="txtID" name="username" required>
            <label for="txtID">用户名(3-10位字符)</label>
        </div>
        <div class="item">
            <input type="password" id="txtCID" name="password" required>
            <label for="txtCID">密码(4-16位字符)</label>
        </div>
        <button class="btn1" type="submit">登录
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </button>
        <button class="btn2" onclick="location.href='register.php'">注册
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </button>
    </form>
</div>

<script>
    document.getElementById('loginForm').addEventListener('submit',function (e){
        const username=document.querySelector('[name="username"]').value;
        const password=document.querySelector('[name="password"]').value;
        const  errors=[];

        if (username.length<3 || username.length>10){
            errors.push('用户名需为3-10位字符');
        }
        if (password.length<4||password.length>16){
            errors.push('密码需为4-16位字符');
        }

        if (errors.length>0){
            e.preventDefault();
            alert(errors.join('\n'));
        }
    });
</script>
</body>

</html>
